package com.servlet.web;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Title: ResponseServlet01
 * @Description:
 * @Auther: py
 * @Version: 1.0
 * @create 2023/12/22 9:09
 */
@WebServlet("/resp01")
public class ResponseServlet01 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            // 响应文本信息
            // 设置响应解析的编码方式
           resp.setCharacterEncoding("utf-8");
           resp.setContentType("text/plain");
           // 设置响应的类型 text/plain 文本类型 text/html 超文本类型 application/json json类型
           // resp.setHeader("Content-Type","text/plain;charset=utf-8");
           resp.getWriter().write("响应成功！!");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
             doGet(req,resp);
    }
}
